package com.android.clinic.app.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewGroup;

import com.android.clinic.app.R;
import com.android.clinic.app.ui.main.view.ClassifyView;

/**
 * Created by cheng on 2018/1/26.
 */
public class HomeClassifyAdapter extends BaseDelegateAdapter {

    public static final int REQ_CLASSIFY = 9527;
    private boolean isUpdate = false;

    public HomeClassifyAdapter(Context context, int... resource) {
        super(context, R.layout.item_home_classify);
    }

    @Override
    protected Object setupViewHolder(@Nullable View convertView, ViewGroup parent, int typeIndex) {
        return new ViewHolder(convertView);
    }

    @Override
    protected void setupBindViewHolder(Object viewHolder, int position, int typeIndex) {
        ViewHolder holder = (ViewHolder) viewHolder;
        if (isUpdate) {
            isUpdate = false;
            holder.classifyView.initData(REQ_CLASSIFY);
        } else {
            holder.classifyView.updateClassify();
        }
    }

    @Override
    public int getItemCount() {
        return 1;
    }

    public void notifyClassify() {
        if (!isUpdate) {
            isUpdate = true;
            notifyDataSetChanged();
        }
    }

    private class ViewHolder extends BaseViewHolder {

        private ClassifyView classifyView;

        public ViewHolder(View itemView) {
            super(itemView);
            classifyView = (ClassifyView) itemView.findViewById(R.id.classify_view);
            classifyView.initUI(mContext, 8, 4);
        }
    }
}
